#include "octnode.hpp"

OctNode::OctNode(OctNode *parent) {
  size=0;
  level=0;
  value=0;
  this->parent=parent;
  children=new QList<OctNode *>();
}

OctNode::~OctNode() {
  removeAllChildren();
  delete children;
}

int OctNode::getNumChildren() {
  return children->size();
}

const Vector3i & OctNode::getPosition() const {
  return pos;
}

void OctNode::setPosition(const Vector3i &pos) {
  this->pos=pos;
}

void OctNode::setPosition(int x,int y,int z) {
  pos << x,y,z;
}

int OctNode::getSize() {
  return size;
}

void OctNode::setSize(int size) {
  this->size=size;
}

int OctNode::getLevel() {
  return level;
}

void OctNode::setLevel(int level) {
  this->level=level;
}

unsigned char OctNode::getValue() {
  return value;
}

void OctNode::setValue(unsigned char value) {
  this->value=value;
}

OctNode * OctNode::getParent() {
  return parent;
}

QList<OctNode *> * OctNode::getChildren() {
  return children;
}

void OctNode::addChild(OctNode *child) {
  children->append(child);
}

void OctNode::removeChild(OctNode *child) {
  children->removeOne(child);
}

void OctNode::removeAllChildren() {
  QListIterator<OctNode *> i(*children);
  while (i.hasNext()) delete i.next();
  children->clear();
}

OctNode * OctNode::getChild(int i) {
  if (i<0 || i>children->size()-1) return NULL;
  else return children->at(i);
}
